%%%-------------------------------------------------------------------
%%% @author Viktor Green <viktor@dhcp-177153.eduroam.chalmers.se>
%%% @copyright (C) 2011, Viktor Green
%%% @doc
%%% Supervisor for peer receiving and sending
%%% @end
%%% Created : 16 Dec 2011 by Viktor Green <viktor@dhcp-177153.eduroam.chalmers.se>
%%%-------------------------------------------------------------------
-module(peer_sup).

-behaviour(supervisor).

%% API
-export([start_link/1]).

%% Supervisor callbacks
-export([init/1]).

-define(SERVER, ?MODULE).

-define(CHILD(I, Type, Args), {I, {I, start_link, Args},
                               permanent, 5000, Type, [I]}).

%%%===================================================================
%%% API functions
%%%===================================================================

%%--------------------------------------------------------------------
%% @doc
%% Starts the supervisor
%%
%% @end
%%--------------------------------------------------------------------
start_link(Socket) ->
    supervisor:start_link({local, ?SERVER}, ?MODULE, [Socket]).

%%%===================================================================
%%% Supervisor callbacks
%%%===================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever a supervisor is started using supervisor:start_link/[2,3],
%% this function is called by the new process to find out about
%% restart strategy, maximum restart frequency and child
%% specifications.
%%
%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
%%                     ignore |
%%                     {error, Reason}
%% @end
%%--------------------------------------------------------------------
init([Socket]) ->
    Recv = ?CHILD(peer_recv, worker, [Socket]),
    Send = ?CHILD(peer_send, worker, [Socket]),
    {ok, {{one_for_one, 1, 60}, [Recv, Send]}}.

%%%===================================================================
%%% Internal functions
%%%===================================================================
